﻿using Newtonsoft.Json.Linq;
using RuoVea.GoFastdfs.Common;
using RuoVea.GoFastdfs.Dto;
using RuoVea.GoFastdfs.Service.Inserface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RuoVea.GoFastdfs.Service
{
    /// <summary>
    /// 文件列表相关逻辑处理
    /// </summary>
    public class FileService: IFileService
    {

        /// <summary>
        /// 获取一级目录
        /// </summary>
        /// <param name="peersGroupName"></param>
        /// <param name="serverAddress"></param>
        /// <returns></returns>
        public List<FileResult> getParentFile(String peersGroupName, String serverAddress)
        {
            return GetFileUtil.getDirOrFileList(peersGroupName, serverAddress, null);
        }

        /// <summary>
        /// 获取指定目录
        /// </summary>
        /// <param name="showUrl"></param>
        /// <param name="serverAddress"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public List<FileResult> getDirFile(String showUrl, String serverAddress, String dir)
        {
            return GetFileUtil.getDirOrFileList(showUrl, serverAddress, dir);
        }


        //    /**
        //     * @description 删除文件
        //     * @param peersUrl peersUrl
        //     * @param md5 md5
        //     * @return boolean
        //     * @author Perfree
        //     */
        //    public Boolean deleteFile(String peersUrl, String md5)
        //    {
        //        Dictionary<String, Object> param = new Dictionary<String, Object>(10);
        //        param.Add("md5", md5);
        //        JObject parseObj = JSONUtil.parseObj(HttpUtil.post(peersUrl + FinalAPI.API_DELETE, param));
        //        return parseObj.getStr("status").equals(FinalAPI.API_STATUS_SUCCESS);
        //    }

        //    /**
        //     * @description 获取文件信息
        //     * @param peersUrl peersUrl
        //     * @param md5 md5
        //     * @return com.perfree.common.ResponseBean
        //     * @author Perfree
        //     */
        //    public ResponseBean details(String peersUrl, String md5)
        //    {
        //        HashMap<String, Object> param = new HashMap<>(10);
        //        param.put("md5", md5);
        //        JSONObject parseObj = JSONUtil.parseObj(HttpUtil.post(peersUrl + FinalAPI.API_GET_FILE_INFO, param));
        //        if (parseObj.getStr("status").equals(FinalAPI.API_STATUS_SUCCESS))
        //        {
        //            FileDetails fileDetails = JSONUtil.toBean(parseObj.getStr("data"), FileDetails.class);
        //        fileDetails.setSize(FileSizeUtil.GetLength(Long.parseLong(fileDetails.getSize())));
        //        fileDetails.setTimeStamp(DateUtil.getFormatDate(new Date(Long.parseLong(fileDetails.getTimeStamp())* 1000)));
        //        fileDetails.setUrl(peersUrl + "/" + fileDetails.getPath().replace("files/","") + "/" + fileDetails.getName());
        //        return ResponseBean.success(fileDetails);
        //    }
        //    return ResponseBean.fail("获取文件信息失败");
        //}
    }
}
